﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.ComponentModel;

using RSEngine.Core;
using RSEngine.Helper;

namespace RSEngine.FilesFormats
{
    sealed public class FileImporter
    {

        #region Import

        public void Import(string path)
        {
            RSBase.ResetId();

            // 3DS
            if (path.ToLower().Trim().EndsWith(".3ds"))
            {
                Import3DSTask task = new Import3DSTask(path);
                Engine.EnqueueTask(task);
            }

            // Collada
            else if (path.ToLower().Trim().EndsWith(".dae"))
            {
                ImportDAETask task = new ImportDAETask(path);
                Engine.EnqueueTask(task);
            }
        }

        #endregion

    }

    #region Import3DSTask

    /// <summary>
    /// Import a 3DS file.
    /// </summary>
    sealed public class Import3DSTask : Task
    {
        private string _path;

        public Import3DSTask(string path)
        {
            _path = path;
        }

        public override void Execute()
        {
            //---- Create a new scene
            Scene scene = new Scene();
            scene.Name = new FileInfo(_path).Name;

            //---- Load the scene
            RSEngine.FilesFormats._3DS.Importer importer = new RSEngine.FilesFormats._3DS.Importer();
            importer.ImportFile(scene, _path, 1.0);

            //---- Optimize the scene
            //SceneOptimizer optimizer = new SceneOptimizer();
            //optimizer.Optimize(scene);

            //---- Update the current scene
            RSEngine.Engine.Scene = scene;
        }
    }

    #endregion

    #region ImportDAETask

    /// <summary>
    /// Import a DAE/Collada file.
    /// </summary>
    sealed public class ImportDAETask : Task
    {
        private string _path;

        public ImportDAETask(string path)
        {
            _path = path;
        }

        public override void Execute()
        {
            //---- Create a new scene
            Scene scene = new Scene();
            scene.Name = new FileInfo(_path).Name;

            //---- Load the scene
            RSEngine.FilesFormats.Collada.Importer importer = new RSEngine.FilesFormats.Collada.Importer();
            importer.ImportFile(scene, _path, 1.0);

            //---- Optimize the scene
            //SceneOptimizer optimizer = new SceneOptimizer();
            //optimizer.Optimize(scene);

            //---- Update the current scene
            RSEngine.Engine.Scene = scene;
        }
    }

    #endregion

}
